﻿@{
    // Cache the image for a minute
    Response.OutputCache(60);

    var photoId = UrlData[0].AsInt();
    var db = Database.Open("PhotoGallery");
    var photo = db.QuerySingle("SELECT * FROM Photos WHERE Id = @0", photoId);
    if (photo == null) {
        Response.SetStatus(HttpStatusCode.NotFound);
        return;        
    }

    Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlPathEncode(photo.FileTitle + photo.FileExtension)));
    new WebImage(photo.FileContents).Write();
}